/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Models.DAO;

import DBConnection.ConnectionFactory;
import Models.Member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author Don
 */
public class Access_DAO {
    
    
    public Member getAccount(String email,String password){
        
        Member accnt = null;

        try{
            
            ConnectionFactory myFactory = ConnectionFactory.getFactory();
            Connection conn = myFactory.getConnection();
            int i = 1; int j = 1;
            PreparedStatement pstmtMember = conn.prepareStatement("SELECT * FROM member WHERE username = ? AND password = ? ");

            
            pstmtMember.setString(j++, email);
            pstmtMember.setString(j++, password);
            

            ResultSet rsMember = pstmtMember.executeQuery();
            
            
            if (rsMember.next()){

                accnt = new Member();
                accnt.setEmail(rsMember.getString("email"));
                accnt.setFirstname(rsMember.getString("firstname"));
                accnt.setFullname(rsMember.getString("firstname")+" "+rsMember.getString("lastname"));
                accnt.setLastname(rsMember.getString("lastname"));
                accnt.setMemberid(rsMember.getInt("memberid"));
                accnt.setPrivlevel(rsMember.getInt("privlevel"));
                //you can get more details here
                return accnt;  
            }
        }
        catch(Exception e){
        
        }
        return accnt;
    }
    
}
